from typing import Annotated
from fastapi import Depends, HTTPException, Path
from sqlalchemy.ext.asyncio import AsyncSession
from starlette.status import HTTP_404_NOT_FOUND

from price_analysis.core.models import db_helper, IncomingSO
from . import crud


async def incoming_so_by_id(
    idx: Annotated[int, Path()],
    session: AsyncSession = Depends(db_helper.get_async_session),
) -> IncomingSO:
    incoming_so = await crud.get_incoming_so(session=session, idx=idx)

    if incoming_so:
        return incoming_so

    raise HTTPException(
        status_code=HTTP_404_NOT_FOUND,
        detail=f"Документ с ID: {id} не найден",
    )
